/**
 *
 */
package gemini.basic.dao.impl;

import gemini.basic.dao.GmnDao;
import gemini.basic.dao.MonthDao;
import gemini.basic.model.AbstractDomain;
import gemini.basic.model.Month;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 *
 */
public class MonthDaoImpl extends HibernateDaoSupport implements MonthDao {

	private GmnDao gmnDao;

	public void setGmnDao(GmnDao gmnDao) {
		this.gmnDao = gmnDao;
	}

	@Override
	public Month getById(int id) {

		DetachedCriteria dtCri = DetachedCriteria.forClass(Month.class);
	
		if (id != AbstractDomain.TRANSIENT_ENTITY_ID) {
			dtCri.add(Restrictions.eq("id", id));
		}

		List<Object> monthList = gmnDao.findByCriteria(dtCri);

		Month result = null;
		if (monthList != null && !monthList.isEmpty()) {
			result = (Month) monthList.get(0);
		}
		return result;
	}

	@Override
	public Month saveOrUpdate(Month month, boolean flush) {
		Month result = null;
		if (flush) {
			result = (Month) gmnDao.saveOrUpdateAndFlush(month);
		} else {
			result = (Month) gmnDao.saveOrUpdate(month);
		}
		return result;
	}

}
